var stbH;  //搜索表格高度
var sConH; //内容显示高度  
function hideSearch(speed){
	speed = speed||"slow";
	var show=1;
    if ($(".searchtbl").css("display") != 'none') {
		stbH = $(".searchtbl").height();
		$(".searchtbl").hide(speed, function(){$(window).resize();});
		$(".searchContainer").height($(".searchContainer").height() + stbH);
		$("#hideSearchBtn").attr("title", "显示查询");
		$("#hideSearchBtn").find("font").removeClass();
		$("#hideSearchBtn").find("font").addClass("icon-down");
		show=2;
	} else {
		$(".searchtbl").show(speed, function() {
			$(".searchtbl").height(stbH);
			$(".searchContainer").height($(".searchContainer").height() - stbH);
			$("#hideSearchBtn").attr("title", "隐藏查询");
			$("#hideSearchBtn").find("font").removeClass();
			$("#hideSearchBtn").find("font").addClass("icon-up");
			$(window).resize();
		});
	}
	var tar = $.event.fix(event).target;
	if (tar && tar.tagName && tar.tagName.toLowerCase() == 'font') {
		$.cookie('showSearch',show,{expires:365});
	}
}
/** 同一列中合并内容相同的行  参数：列的jquery选择器，此列前是序号列并且需要合并序号列 */
$.fn.spanColCell = function(options){
	opt = $.extend({},$.fn.spanColCell.defaults,options);
	var tds = this;
	function getText(td){
		var text = (td=$(td)).text().replace('_','-');
		var idx = opt.relyPreCell,ptd=td;
		while(idx-->0&&(ptd=ptd.prev()).length>0){
			text = ptd.text().replace('_','-')+"_"+text;
		}
		return text;
	}
	var text = getText(tds[0]);
	var begin = 0,index=1;
	for(var i=0;i<=tds.length;i++){
		if(i==tds.length||text!=getText(tds[i])){
			$(tds[begin]).attr('rowSpan',i-begin);
			if(opt.isAfterIndex){
				$(tds[begin]).prev().attr('rowSpan',i-begin).text(index++);
			}
			for(var j=begin+1;j<i;j++){
				if(opt.isAfterIndex){
					$(tds[j]).prev().remove();
				}
				$(tds[j]).remove();
			}
			text = getText(tds[i]);begin=i;
		}
	}
};
$.fn.spanColCell.defaults={isAfterIndex:false,relyPreCell:0};
function spanTblRow(selector,opt){
}
function spanTblCol(from,to,text,attrs,context){
	context = window._spanSelf||context||document;
	var fth = $('thead>tr>th[field='+from+']:first',context);
	var tth = $('thead>tr>th[field='+to+']:first',context);
	if(fth.length==0||tth.length==0||fth.parent().length==0||tth.parent().length==0||fth.parent()[0]!=tth.parent()[0]){
		return;//如果找不到指定的两列，或者指定的两列不在同一行，则不执行合并操作
	}
	var seqwront=true;
	fth.nextAll().each(function(){
		if(this==tth[0])seqwront=false;
	});
	if(seqwront){//如果起始位置不对，则进行置换
		var tmp = tth;tth=fth;fth=tmp;
	}
	var tr = fth.parent();
	if(fth.attr('rowspan')==1||tth.attr('rowspan')==1){
		tr.after('<tr></tr>');
		tr.find('th,td').each(function(){
			this.rowSpan=this.rowSpan+1;
		});
	}
	var ntr = tr.next();
	var spanth = $('<th field="'+fth.attr('field')+'" '+attrs+'>'+text+'</th>');
	fth.before(spanth);
	var end=false,colspan=0;
	fth.add(fth.nextAll()).each(function(){
		if(!end){
			ntr.append(this);
			this.rowSpan=this.rowSpan-1;
			colspan+=this.colSpan;
			if(this==tth[0])end=true;
		}
	});
	spanth[0].colSpan=colspan;
}
//$.fn.search
function getSelectHtml(ary,blank){//将给定数组转换为select所需的option代码
	 ary=typeof(ary)=='string'?ary.split(','):ary;
	 var selhtm=blank?'<option value=""> </option>':'';
	 for(var i=0;i<ary.length;i++){
		 var tmp=ary[i].indexOf(':')>=0?ary[i].split(':'):[ary[i],ary[i]];
		 selhtm+='<option value="'+tmp[0]+'">'+tmp[1]+'</option>';
	 }
	 return selhtm;
}
$.fn.floatThead=function(opt,data){
	var th=$(this);
	if(!th.attr('tagName')||th.attr('tagName').toUpperCase()!='TABLE'){
		return th;//只处理TABLE标签
	}
	if('resize'==opt){
		if(par=th.data('floatThead').container){
			var hdiv = $('>tbody>tr:first>td>div',par);
			var bdiv = $('>tbody>tr:last>td>div',par);
			th.css('width',data.width-18);
			var hei = data.height;
			data.height=hei-hdiv.height();
			bdiv.css(data);
			$('>div>div',hdiv).width($('>table',bdiv).outerWidth());
			hdiv.width(bdiv.width());
			data.height=hei-hdiv.height();
			bdiv.css(data);
			$('>div>div',hdiv).width($('>table',bdiv).outerWidth());
		}
		return th;
	}
	else if('options'==opt){
		return th.data('floatThead').options;
	}
	else if('panel'==opt){
		return th.data('floatThead').container;
	}
	else if('thead'==opt){
		return th.data('floatThead').thead;
	}
	else{
		if(th.data('floatThead')){//避免重复执行
			return th;
		}
		opt = $.extend({},{width:th.width(),height:'100%'},opt);
		if(opt.height=='100%'||opt.height=='auto'){
			opt.height=th.parent().height();
		}
		if(opt.width=='100%'||opt.width=='auto'){
			opt.width=th.width();
		}
		th.before(par=$('<table class=float-table cellpadding=0 cellspacing=0><tr><td><div><div><div></div></div></div></td></tr><tr><td><div></div></td></tr></table>').css('width',opt.width));
		th.css({margin:'0px',width:opt.width}).attr('align','left');
		$('>tbody>tr:last>td>div',par).css({overflow:'auto',width:opt.width,'text-align':'left'}).append(th).data('header',$('>tbody>tr:first>td>div',par)).scroll(function(){
			$(this).data('header').scrollLeft($(this).scrollLeft());
		});
		var thead = null;
		$('>tbody>tr:first>td>div',par).css({overflow:'hidden',width:'100%'});
		$('>tbody>tr:first>td>div>div',par).css({width:'99999px'});
		$('>tbody>tr:first>td>div>div>div',par).append(thead=createFloatHeader(th).css({margin:'0px',width:'100%'}));
		$('>thead>tr',th).hide();
		th.data('floatThead',{options:opt,container:par,thead:$('thead',thead)});
		th.floatThead('resize',opt);
		return th;
	}
	function createFloatHeader(tbl){
		var header = $('<table style="table-layout:fixed;"><colgroup>'+
				($('colgroup',tbl).html()||'')+'</colgroup><thead>'+($('thead',tbl).html()||'')+'</thead></table>');
		if($.browser.msie&&$.browser.version<8){//解决IE6,IE7下浮动表头错位的现象
			$('colgroup col:last',header).each(function(){
				if(this.width&&this.width.indexOf('%')<0)this.width=parseInt(this.width)+2;
			});
		}
		var ary = 'class,border,cellpadding,cellspacing'.split(',');
		for(var i=0;i<ary.length;i++){
			header.attr(ary[i],tbl.attr(ary[i]));
		}
		return header;
	}
};
function optnAdvSearchWin(url){
	 if(parent.window[$('form').attr('action')]=='allSrh'){//第一次查询时，将本页面清空，增加IFRAME，在IFRAME中执行查询，用来保存查询条件，在子页面中查询时就执行父页面中的查询动作
		 parent.$('#allSrhDiv').window('open');return;
	 }
	 if($('#allSrhDiv').length==0){
		 var type = $.cookie('allSrhType')=='adv'?'adv':'base';
		 $('<div id=allSrhDiv style="overflow:hidden;width:200px;"><div fit=true><div region=center border=false>'+
		 	'<form id=allSrhForm method=post><input type=hidden name="search.allSrhConds"><table id=allSrhTbl class=tb_add_th style="width:100%;"></table></form>'+
    	 	'</div><div region="south" border="false" style="display:none;height:35px;padding:5px 10px 0px 0px;border-top:1px solid #99BBE8;text-align:right;">'+
	 		'<span style="float:left;padding:3px 0px 0px 10px;color:red;text-align:left;"><input type=checkbox id=allsrhAdvChk style="float:left;">'+
	 		'<label style="float:left;" for=allsrhAdvChk>高级逻辑查询</label></span>'+
	 		'<a id="addSrhCondBtn" href="javascript:void(0)" style="display:none;" iconCls="icon-add">增加条件</a>'+
	 		'<a id="allSrhBtn" href="javascript:void(0)" iconCls="icon-search">查询</a></div></div></div>').appendTo('body')
	 		.window({width:500,height:430,title:'请选择查询条件',iconCls:'icon-search',minimizable:false,collapsible:false,maximizable:false,closable:true,shadow:true});
    	 var w={};
		 $.ajax({url:url,data:{op:'loadSrhConds'},success:function(html){//获取查询关键字
			 /* text:查询条件文本,
			  * field:查询用的字段,
			  * type:类型text文本date日期num数字sel选择,
			  * sign:type=text时需要此字段，默认值为LIKE，可以选用其它比较符号,
			  * call:对自动生成的input或select进行脚本处理，如生成下拉树，下拉框等,
			  * format:type=date时做为日期框的格式串
			  * data:type=sel时做为选择框的内容填充*/
			 try{
				 w.srhConds=$.parseJSON(html);
			 }catch(e){$('#allSrhTbl').html('<tr><td style="font-size:24px;color:red;">服务器返回内容错误</td></tr><tr><td>'+html+'</td></tr>');}
			 w.srhConds.andorsel='<select style="width:55px;">'+getSelectHtml(['AND:与','OR:或'])+'</select>';
			 w.signs={text:'<select style="width:55px;">'+getSelectHtml(['LIKE:包含','==:等于','!=:不等'])+'</select>'
					 ,sel:'<select style="width:55px;">'+getSelectHtml('==:等于,!=:不等')+'</select>'
					 ,num:'<select style="width:55px;">'+getSelectHtml(['>:大于','>=:大于等于','==:等于','!=:不等','<:小于','<=:小于等于'])+'</select>'
					 ,date:'<select style="width:55px;">'+getSelectHtml(['>=:大于等于','==:等于','<=:小于等于'])+'</select>'};
			 w.srhConds.textary=[];
			 for(var i=0;i<w.srhConds.length;i++){
				 if(!w.srhConds[i].text)continue;
				 w.srhConds.textary.push(w.srhConds[i].field+':'+w.srhConds[i].text);
				 w.srhConds[w.srhConds[i].field]=w.srhConds[i];
				 w.srhConds['_default']?'':(w.srhConds['_default']=w.srhConds[i]);
			 }
	    	 initSrhTable(type);
	    	 $('#allSrhBtn').parent().show();
		 }});
		 function getSrhHtml(type){//查询窗口的TABLE内容
			 var htm='';
		   	 for(var i=0;i<w.srhConds.length;i++){
		   		 if(!w.srhConds[i].text)continue;
		   		 htm+=getSrhRowHtml(type,w.srhConds[i]);
		   	 }
			 return htm;
		 }
		 function getSrhRowHtml(type,o){//查询窗口中的每行内容
			 if(!o)return'';
			 htm = '<tr height="31px">';
			 if(type=='adv'){//高级逻辑查询内容
				 htm+='<td nowrap style="width:40%">'+w.srhConds.andorsel+'<select text=1 style="width:106px;">'+
				 getSelectHtml(w.srhConds.textary)+'</select>'+
				 w.signs[o.type]+'</td><td>'+
				 (o.type=='sel'?'<select f="'+o.field+'" style="width:180px;">'+
				 getSelectHtml(o.data,true)+'</select>':'<input f="'+o.field+'"'+(o.type=='date'?' class="Wdate" onclick="WdatePicker('+
				 (o.format?"{dateFmt:'"+o.format+"'}":'')+')" readonly=true':'')+' type=text style="width:180px;" />');
			 }else{//更多基本查询
				 htm+='<th width="35%">'+o.text+'</th><td>'+(o.type=='date'?'<input type=text f="'+o.field+'" style="width:113px" class="Wdate" onclick="WdatePicker('+(o.format?"{dateFmt:'"+o.format+"'}":'')+')" readonly=true />'+
						 '至<input type=text f="'+o.field+'" style="width:113px" class="Wdate" onclick="WdatePicker('+(o.format?"{dateFmt:'"+o.format+"'}":'')+')" readonly=true />':(o.type=='num'?'大于等于<input type=text f="'+o.field+'" style="width:71px" maxLength="11"/>'+
						 '小于等于<input type=text f="'+o.field+'" style="width:71px" maxLength="11"/>':(o.type=='sel'?'<select f="'+o.field+'" style="width:240px;">'+getSelectHtml(o.data,true)+'</select>':'<input f="'+o.field+'" type=text style="width:240px;" />')));
			 }
			 return htm+'</td></tr>';
		 }
    	 function initSrhTable(type){//填充查询窗口的内容
			 $('#allSrhTbl').html(getSrhHtml(type));
			 $('#addSrhCondBtn').css('display',type=='adv'?'':'none');
	    	 $('#allSrhDiv>div').layout({width:600,height:500});
	    	 $('#allSrhDiv select[text]').change(advSelChange).each(function(i){
	    		 $('option',this)[i].selected=true;
	    	 });
	    	 $('#allSrhTbl *[f]').each(initInputBox);
    	 }
    	 function advSelChange(){//高级查询的字段选择框事件
    		 var o = w.srhConds[this.value];
    		 $(this).next().remove();$(this).after(w.signs[o.type]);
    		 $(this).parent().next().html(o.type=='sel'?'<select f="'+o.field+'" style="width:180px;">'+getSelectHtml(o.data,true)+'</select>':'<input f="'+o.field+'"'+(o.type=='date'?' class="Wdate" onclick="WdatePicker()" readonly=true':'')+' type=text style="width:180px;" />').find('*[f]').each(initInputBox);
    	 }
    	 function initInputBox(){
    		 var o=w.srhConds[$(this).attr('f')];
    		 if(o.call){
    			 try{
        			 if(typeof(o.call)=='string')o.call=eval(o.call);
        			 o.call.call(this);
    			 }catch(e){if(window.console)console.log('error:'+e);}
    		 }
    		 if(o.type=='sel'){//选择的可以使用多选
    			 $(this).combobox({multiple:true,width:$(this).width()+8}).combobox('setValue','');//初始值为空
    			 $('.combobox-item:first[value=" "]',$(this).combobox('panel')).remove();//去掉第一个空选项
    		 }
    	 }
    	 $('#addSrhCondBtn').linkbutton().click(function(){//增加查询条件
    		 var type = $('#allsrhAdvChk').attr('checked')?'adv':'base';
    		 $('#allSrhTbl').append(getSrhRowHtml(type,w.srhConds['_default']));
	    	 $('#allSrhTbl tr:last input[f]').each(initInputBox);
	    	 $('#allSrhTbl tr:last select[text]').change(advSelChange);
		 });
		 $('#allSrhBtn').linkbutton().click(function(){//点击查询按钮
			 var type = $('#allsrhAdvChk').attr('checked')?'adv':'base';
			 var sql='1=1';
			 $('#allSrhTbl tr').each(function(){
				 var eles=$('*[f]',this);
				 eles.each(function(){try{$(this).val($(this).combo('getValue')||'');}catch(e){;}});
	    		 var o=w.srhConds[eles.attr('f')];
	    		 var val=eles.val().replace(/'/g,"''"),val2=eles.length==2?eles.last().val().replace(/'/g,"''"):'';
	    		 if(val==''&&val2=='')return;
	    		 if(type=='adv'){//高级模式
	    			 var sels=eles.parent().prev().find('select');
					 var sign=sels[2].value.replace('==','=');//比较符 = != > >= < <= like
					 var opreator = ' '+sels[0].value+' ';//AND OR
    				 if(o.type=='text'){
    					 sql += opreator+o.field+' '+(sign=='LIKE'?" like '%"+val+"%'":sign+"'"+val+"'");
    				 }else if(o.type=='date'){
    					 sql += opreator+"to_char("+o.field+",'"+o.format+"')"+sign+"'"+val+"'";
    				 }else if(o.type=='num'){
    					 sql += opreator+o.field+sign+val;
    				 }else if(o.type=='sel'){
    					 try{
    						 if((val=eles.combo('getValues')).length>1){
    	    					 sql += opreator+o.field+(sign=='='?'':' not')+" in ('"+val.join("','")+"')";
    						 }
    						 else{
    	    					 sql += opreator+o.field+sign+"'"+val+"'";
    						 }
    					 }catch(e){
        					 sql += opreator+o.field+sign+"'"+val+"'";
        			     }
    				 }
	    		 }
	    		 else{
    				 if(o.type=='text'){
    					 o.sign=o.sign||'LIKE';sql += ' and '+o.field+' '+(o.sign.toUpperCase()=='LIKE'?" like '%"+val+"%'":o.sign.replace('==','=')+"'"+val+"'");
    				 }else if(o.type=='date'){
    					 sql += (val==''?'':" and "+o.field+">=to_date('"+val+('1900-01-01 00:00:00'.substr(val.length))+"','yyyy-mm-dd hh24:mi:ss')")+
    							(val2==''?'':(val2.length<10&&o.format?" and to_char("+o.field+",'"+o.format+"')<='"+val2+"'":" and "+o.field+"<=to_date('"+val2+('1900-01-01 23:59:59'.substr(val2.length))+"','yyyy-mm-dd hh24:mi:ss')"));
    				 }else if(o.type=='num'){
    					 sql += (val==''?'':" and "+o.field+">="+val)+(val2==''?'':" and "+o.field+"<="+val2);
    				 }else if(o.type=='sel'){
    					 try{
    						 if((val=eles.combo('getValues')).length>1){
    	    					 sql += " and "+o.field+" in ('"+val.join("','")+"')";
    						 }
    						 else{
            					 sql += " and "+o.field+"='"+val+"'";
    						 }
    					 }catch(e){
        					 sql += " and "+o.field+"='"+val+"'";
        			     }
    				 }
	    		 }
			 });
			 if(sql.indexOf('1=1 and ')==0)sql=sql.substr('1=1 and '.length);
			 $('#allSrhForm>input:first').val(sql);
			 if(window[$('form').attr('action')]!='allSrh'){//第一次查询时清空页面，并增加IFRAME
				 window[$('form').attr('action')]='allSrh';
    			 $('#allSrhForm').attr({'action':$('form[name!=editForm][id!=allSrhForm]').attr('action'),'target':'allSrhFrm'});
				 $('form[name!=editForm][id!=allSrhForm]').remove();
				 $('<iframe width=100% height=100% frameborder=0 id=allSrhFrm name=allSrhFrm></iframe>').appendTo('body');
				 $(window).unbind('resize').resize(function(){
					 $('#allSrhFrm').css({width:$(window).width(),height:$(window).height()});
				 });
				 $(window).resize();
			 }
			 $('#allSrhForm').submit();
    		 $('#allSrhDiv').window('close');
		 });
		 $('#allsrhAdvChk').attr('checked',type=='adv').click(function(){//点击高级逻辑查询
			 $.cookie('allSrhType',type = this.checked?'adv':'base',{expires:365});//保存1年
	    	 initSrhTable(type);
		 });
	 }
	 $('#allSrhDiv').window('open');
}
$(function(){
	if(window.initSearch)return;//页面重复加载本js文件时不会重复执行
	window.initSearch = true;
    if(document.location.href.indexOf('http://localhost')==0){//本机测试时显示1024宽度虚线，便于测试
    	$('<div style="position:absolute;left:824px;top:3px;width:1px;height:25px;border-left:1px dashed #ccc;"></div>').appendTo('body');
    }
	$.fn.slidePos = function(name,val){
		if(name!='top'&&name!='left')return;
		val = (''+val).toLowerCase().replace('px','');
		$(this).attr('slide-pos-'+name,val);
		var thiz = $(this);
		function slidePosFun(){
			var ov=thiz.position()[name];
			var nv = thiz.attr('slide-pos-'+name);
			if(ov!=nv){
				var step = parseInt(Math.max(1,Math.abs(nv-ov)/10));
				if(ov<nv)ov+=step;else ov-=step;
				thiz.css(name,ov);
				if(Math.abs(nv-ov)>=1)setTimeout(slidePosFun,10);
			}
		}
		slidePosFun();
	};
	if($(document.body).height()<$(window).height())$('body').css('height',$(window).height());
	$(window).data("scroll-event",[]);//存放页面滚动时调用的方法
	window.do_scroll_event = function(){
		var ary = $(window).data("scroll-event");
		for(var i=0;i<ary.length;i++){
			try{ary[i]();}catch(e){;}
		}
		window.last_scroll_time=new Date().getTime();
	};
	$('.searchtbl input[type=text]').keyup(function(){
		if($.event.fix(event).keyCode==13){//在输入框内敲回车相当于查询按钮
			$('#search').click();
		}
	});
	$('.toolbar').each(function(){//如果按钮栏没有按钮，则直接去除按钮栏
		var tb = $(this);
		if((tb.find('a').length==0&&!tb.attr('force')) || (tb.find('a').length==1&&tb.find('a').attr('id')=='hideSearchBtn')){
			tb.remove();
		}
	});
	if($('.toolbar').length>0){//按钮区
		$('.toolbar').each(function(){
			var tb = $(this);
			tb.css('width',$(window).width());
			if(tb.find('b.tb-head').length==0)tb.prepend('<b class="tb-head">&nbsp;</b>');
			if($.browser.msie&&$.browser.version<8){//IE6，nobr   css('width',$(this).text().replace(/[^x00-xff]/,'aa').length*6+20);
				tb.find('>a').each(function(){$(this).width($(this).text().replace(/^\s|\s$/g,'').replace(/[^x00-xff]/g,'aa').length*7+20);});
			}
		});
		if($(document).scrollTop()==0){
			//setTimeout("$(document).scrollTop($($('.toolbar')[0]).position().top);do_scroll_event();",10);
		}
	}
	if(false&&$(window).height()<600){//IE6或小屏幕时使用浮动表头
		floatSearchTable();
	}
	else{//大屏幕时使用固定表头
		if($('.searchContent').length==1&&$('.searchContent colgroup').length==1&&!$('.searchContent').attr('nofloat')){//数据展示区域
			if($('.searchtbl').length>0&&$('.searchtbl').height()>70){//查询区域超过两行的打开页面时自动隐藏，当展开查询后再次进入页面不自动隐藏
				if(!$.cookie('showSearch')){
					//显示黄色提示框，提示点击按钮后可以显示查询
					//$(".searchtbl").show();hideSearch(10);//20120921修改为默认显示查询条件
				}
				else{
					if($.cookie('showSearch')==2){
						$(".searchtbl").show();hideSearch(10);
					}
				}
			}
			if($('.searchtbl').length==0){
				$('#hideSearchBtn').remove();
			}
			$('html,body').css('overflow','hidden');
			$('.searchContent').css('width','100%');
			var tblDiv = $('<div class=searchContainer></div>');
			$('.searchContent').before('<div class=headerContainer></div>').before(tblDiv).appendTo(tblDiv);
			var header=$('.headerContainer').append($('<div><div></div></div>'));
			$('>div>div',header).append(createFloatHeader().css({display:'',position:''})).css({'padding-left':$('.searchContent').position().left,height:$('#float_tbl_head').outerHeight()});
			header.css({width:$(window).width(),height:$('#float_tbl_head').outerHeight()});
			$('>div',header).css({width:$('#float_tbl_head').width()+50,height:$('#float_tbl_head').outerHeight()});
			$('.searchContent>thead').hide();
			if($.browser.msie){
				$('.searchContent>thead').remove();
			}
			$('.searchContent,.searchContent>tbody>tr:first td').css('border-top','0px');
			$(window).resize(function(){
				var hei=$(window).height()-$('.searchContainer').position()['top'];
				hei-=$('.page_tbl').length==1?($(window).height()-$('.page_tbl').position()['top']):0;
				$('.searchContainer').height(hei).width($(window).width());
				$('body').height($(window).height()).width($(window).width());
				$('.headerContainer,.toolbar').width($(window).width());
				var diff=Math.abs($('.searchContent').width()-$('.searchContainer').width());
				if(diff>15&&diff<25){
					$('.searchContainer .searchContent').width($('.searchContainer').width()-20);
				}
				else{
					$('.searchContent').width($('.searchContainer').width()-3);
				}
				$('.headerContainer').css({height:$('#float_tbl_head').outerHeight()});
				$('.headerContainer>div>div,#float_tbl_head').css({width:($('.searchContent>tbody>tr').length==0?$(window).width()-3:$('.searchContent').width()+2)});
			});
			$('.searchContainer').scroll(function(){
				$('.headerContainer').scrollLeft($('.searchContainer').scrollLeft());
			});
			$(window).resize();
		}
	}
	function floatSearchTable(){//浮动表头格式的固定表头
		if($('.searchtbl').length>0){//查询区域
			$(window).data("scroll-event").push(function(){//随左右滚动条自动显示
				$('.searchtbl').css('margin-left',$(document).scrollLeft());
			});
		}
		if($('.toolbar').length>0){//按钮区
			$(window).data("scroll-event").push(function(){//随左右滚动条自动显示
				$('.toolbar>b.tb-head').css('width',$(document).scrollLeft());
			});
			$('.toolbar>b.tb-head').css('display','none');
			if($('.toolbar').length==1){//如果只有一个按钮区，则浮动按钮
				var toolbox = $('<div id="toolbox"></div>').insertBefore($('.toolbar'));
				toolbox.css({width:$('.toolbar').width(),height:$('.toolbar').height()});
				toolbox.append($('.toolbar'));
			}
		}
		if($('.searchContent').length>0){//数据展示区域
			//如果只有一个表格，且表格中有colgroup，同时表格属性中未定义nofloat属性时，浮动表头
			if($('.searchContent').length==1&&$('.searchContent colgroup').length==1&&!$('.searchContent').attr('nofloat')){
				//自动定位到表头行
				$('.searchContent').parent().append(createFloatHeader());/*
				if($('.toolbar').length==1&&!$('.toolbar').attr('nofloat')){//是否浮动按钮组
					var cols = 0;
					$('#float_tbl_head thead tr:first th').each(function(){cols+=this.colSpan;});
					$('#float_tbl_head thead').prepend('<tr><td id="tool_td" colspan=1000></td></tr>');
					$('#tool_td').attr('colspan',cols);
				}*/
				do_scroll_event();
				$('#float_tbl_head').slidePos('left',$('.searchContent').position().left);
				$('<div id=float_tbl_head_div style="background:#fff;position:fixed;top:0px;left:0px;"><table width=100% border=0 cellpadding=0 cellspacing=0>'+($('.toolbar').length==1&&!$('.toolbar').attr('nofloat')?
						'<tr><td id=tool_td></td></tr>':'')+'<tr><td id=float_tbl_head_td><div style="overflow:hidden;width:100%;"></div></td></tr></table></div>').appendTo('body');
				$('#float_tbl_head_td>div').append($('#float_tbl_head').css({position:'',display:''})).height($('#float_tbl_head').height());
				$('#float_tbl_head_div').css('border-top','0px');
				$('#float_tbl_head_div,#float_tbl_head').css('display','none');
				if($.browser.msie&&$.browser.version<7){
					$('#float_tbl_head_div').css({position:'absolute',left:'expression($(window).scrollLeft())',top:'expression($(window).scrollTop())'});
				}
				$(window).scroll(function(){
					$('#float_tbl_head_td>div').scrollLeft($(window).scrollLeft());
				});
				$(window).resize(function(){
					$('#float_tbl_head_div,#float_tbl_head_td>div').width($(window).width());
					$('#float_tbl_head').width($('.searchContent').width()+1);
				});
				$(window).resize();
				$(window).data("scroll-event").push(function(){//随上下滚动条滚动自动将表头浮动
					if($(document).scrollTop()>$('.searchContent').position().top){
						if($('#float_tbl_head_div').css('display')=='none'){
							$('#float_tbl_head_div,#float_tbl_head').css('display','block');
							$('.toolbar>b.tb-head').css('display','none');
							$('#float_tbl_head_td>div').scrollLeft($(window).scrollLeft());
						}
						if($('#tool_td').length==1&&$('#tool_td .toolbar').length==0)$('#tool_td').append($('.toolbar'));
						//$('#float_tbl_head').slidePos('top',$(document).scrollTop());
					}
					else{
						$('#float_tbl_head_div,#float_tbl_head').css('display','none');
						$('.toolbar>b.tb-head').css('display','block');
						//$('#float_tbl_head').css('top',0);
						if($('#tool_td').length==1&&$('#tool_td .toolbar').length==1)$('#toolbox').append($('.toolbar'));
					}
				});
			}
			//自动将页面定位到刚才修改（处理）的记录
			if(window.lastModifyId&&window.lastModifyId!='null'){
				setTimeout(function(){
					try{$(document).scrollTop($('input[value="'+window.lastModifyId+'"]').position().top-$(window).height()/2+30);}catch(e){;}
				},300);
			}
		}
		if($('.page_tbl').length==1){//数据分页区域
			$('.page_tbl').parent().append('<br/><br/><br/>');
			$('.page_tbl').attr('id','page_tbl');
			$('#page_tbl').addClass("page_tbl_float");
			$('#page_tbl').css({position:'fixed',bottom:'0px',left:'0px'});
			if($.browser.msie&&$.browser.version<7){
				$('#page_tbl').css({position:'absolute',left:'expression($(window).scrollLeft())',top:'expression($("body").height()-$(window).height()-$(window).scrollTop()+)'});
			}
			/*
			var f = function(){//随左右滚动条自动显示
				$('#page_tbl').slidePos('left',$(document).scrollLeft());
				var hei=0;
				$('#page_tbl tr').each(function(){hei+=$(this).height();});
				$('#page_tbl').slidePos('top',$(document).scrollTop()+$(window).height()-Math.max(hei,30,$('#page_tbl tr').height()));
			};f();
			$(window).data("scroll-event").push(f);
			$(window).resize(function(){//随窗口大小变化宽度
				$('#page_tbl').css('width',$(window).width());
			});*/
		}
		$(window).resize(function(){//窗口大小变化时调整各浮动元素位置
			do_scroll_event();
		});
		$(window).scroll(function(){//滚动时调用滚动代码
			var t = window.last_scroll_time;
			if(t&&new Date().getTime()-t>300){
				do_scroll_event();
			}
			else{
				setTimeout(function(){if(new Date().getTime()-window.last_scroll_time>300)do_scroll_event();},300);
			}
			if(!t)window.last_scroll_time=new Date().getTime();
		});
	}
	function createFloatHeader(){
		var header = $('<table id="float_tbl_head" style="table-layout:fixed;position:absolute;top:0px;left:0px;display:none;"><colgroup>'+
				($('.searchContent colgroup').html()||'')+'</colgroup><thead>'+($('.searchContent thead').html()||'')+'</thead></table>');
		if($.browser.msie&&$.browser.version<8){//解决IE6,IE7下浮动表头错位的现象
			$('colgroup col:last',header).each(function(){
				if(this.width&&this.width.indexOf('%')<0)this.width=parseInt(this.width)+2;
			});
		}
		var ary = 'border,cellpadding,cellspacing'.split(',');
		for(var i=0;i<ary.length;i++){
			header.attr(ary[i],$('.searchContent').attr(ary[i]));
		}
		return header;
	}
	initSearchTable($('.searchContent'));//数据展示区域
});

//获取选中的行的记录ID，以数组格式封装字符串
function getSelIds(ele){
	var ary = [];
	ele = ele||this;
	$(findForm(ele)).find('input[name="chkSelf"]').each(function(){
		if(this.checked)ary.push(this.value);
	});
	return ary;
}
//获取选中的行，以数组格式封装TR对象
function getSelTrs(ele){
	var ary = [];
	ele = ele||this;
	$(findForm(ele)).find('input[name="chkSelf"]').each(function(){
		if(this.checked)ary.push(findParent(this,'tr'));
	});
	return ary;
}
//根据记录ID查找指定行，返回TR对象
function getTrById(id){
	var i = $('input[type="checkbox"][value="'+id+'"]');
	if(i.length>0)return findParent(i[0],'tr');
}
//跳转到指定页
function goPage(page){
	$('input[name="page"]').val(page);
	findForm(this).submit();
}
//重新指定每页行数
function setRows(){
	findForm(this).submit();
}
//给定一个元素及指定HTML标签，向上查找元素的父元素，直到父元素的标签与指定标签匹配
function findParent(ele,tag){
	if(!ele||!tag)return null;
	ele = $(ele);tag = tag.toLowerCase();
	while(ele[0]&&ele[0].tagName&&ele[0].tagName.toLowerCase()!=tag){
		ele = ele.parent();
	}
	if(ele[0]&&ele[0].tagName&&ele[0].tagName.toLowerCase()==tag){
		return ele[0];
	}
	return null;
}
//查找指定元素所在的FORM对象，找不到时返回页面的第一个FORM
function findForm(ele){
	if(ele==null)return $('form')[0];
	ele = findParent(ele,'form');
	return ele||$('form')[0];
}
//为查询结果增加互动效果，1.全选框动作；2.指定列点击后排序；3.数据隔行变色；4.鼠标移动到行上变色；
//5.鼠标单击行时选中第一列复选框；6双击行查看信息
function initSearchTable(tbls){
	tbls = $(tbls);
	if(tbls.length==0)return;
	maxWidth = 0;
	tbls.each(function(){
		var tbl = $(this);
		maxWidth = Math.max(maxWidth,tbl.width()+tbl.position().left);
		var chkAll = $('input[name="chkAll"]');
		chkAll.click(function(){//全选复选框事件，考虑浮动表头的全选框
			var chks = $('input[name="chkSelf"]');
			chks.attr('checked',$(this).attr('checked'));
			$('>tbody>tr',tbl).toggleClass('sel',this.checked);
		});
		$('table.searchContent,table#float_tbl_head').each(function(){
			var tbl = $(this);
			var trs = tbl.find('thead tr');
			if(trs.length>1){//多行表头处理样式，考虑浮动表头的样式
				trs.addClass('multi2');
				$(trs[0]).removeClass('multi2');$(trs[0]).addClass('multi1');
				for(var i=0;i<trs[0].cells.length;i++){
					if(trs[0].cells[i].rowSpan==trs.length)$(trs[0].cells[i]).addClass('rowspan');
				}
				$(trs[trs.length-1]).removeClass('multi2');$(trs[trs.length-1]).addClass('multi3');
			}
			var tds = tbl.find('thead th');//点击表头列排序处理
			function sortData(){
				var sort = $(this).attr('sort');
				if(!sort)return;
				var f = findForm(this);
				f['sort'].value=f['sort'].value.replace(/\s+[^,]*,/,',');
				if(f['sort'].value != sort)f['order'].value='';
				var order = this.order = f['order'].value!='asc'?'asc':'desc';
				if(sort.indexOf(',')>0)sort = sort.replace(/,/,' '+order+',');
				$(this).addClass('datagrid-sort-asc');
				$(this).addClass('datagrid-sort-desc');
				$(this).addClass('datagrid-sort-'+order);
				f['order'].value = order;
				f['sort'].value = sort;
				f.submit();
			}
			var f = findForm(this);
			var fsort=null,forder=null;
			try{
				fsort = f['sort'].value;
				forder = f['order'].value;
				fsort=fsort.replace(/\s+[^,]*,/,',');
			}catch(e){;}
			tds.each(function(){//鼠标移出到表头列上时背景复原
				var sort = $(this).attr('sort');
				if(sort){//排序字段名
					$(this).css('cursor','pointer');
					$(this).append('<span class="datagrid-sort-icon"></span>');
					$(this).attr('order',forder);
					$(this).click(sortData);
					if(fsort==sort){
						$(this).addClass('datagrid-sort-'+forder);
						$('.datagrid-sort-icon',this).css('background-image',$('.datagrid-sort-icon',this).css('background-image'));//解决谷歌浏览器下“向上箭头”不显示的BUG
					}
				}
			});
		});
		var selChange = tbl.attr('selChange');//行选中变化事件
		try{selChange = eval(selChange);}catch(e){;}
		var trs = tbl.find('tbody>tr');
		trs.click(function(e){//单击行，变更第一列的复选框的状态
			e = $.event.fix(e);
			var tr = this;
			if(selChange&&typeof(selChange)=='function'){//行选中变化事件实现
				setTimeout(function(){selChange(getSelIds(tr));},200);
			}
			var chk = $($(this).data('rowTrs')[0]).find('td>input[name="chkSelf"]');//找到第一列单元格中的复选框
			if(chk.length==1&&chk[0]!=e.target&&chk.attr('type').toLowerCase()=='checkbox'){
				chk.attr('checked',!chk.attr('checked'));
			}
			if(chk.attr('checked')){//根据复选框状态对行背景进行控制
				$(this).data('rowTrs').addClass('sel');
			}else{
				$(this).data('rowTrs').removeClass('sel');
			}
		});
		trs.mouseover(function(){//鼠标移动到行上背景变色
			$(this).parent().find('tr').removeClass('over');
			var css = $(this).data('rowTrs').attr('class');
			if(css&&css.toString().indexOf('sel')<0){//如果已经选中的行，不再变背景色
				$(this).data('rowTrs').addClass('over');
			}
		});
		var rowi = 0;//隔行变色
		for(var i=0;i<trs.length;i++,rowi++){
			$(trs[i]).addClass('tr'+(rowi%2));
			var rowTrs = $(trs[i]);
			$(trs[i]).data('rowTrs',rowTrs);
			var span = trs[i].cells[0].rowSpan;
			for(var j=0;j<span-1&&i<trs.length-1;j++){
				$(trs[++i]).addClass('tr'+(rowi%2));
				rowTrs.push(trs[i]);$(trs[i]).data('rowTrs',rowTrs);
			}
		}
		//trs.addClass(function(i){return 'tr'+(i%2);});
		var dbclick = tbl.attr('dbclick');
		if(dbclick){//双击行事件
			try{
				dbclick = eval(dbclick);
				if(typeof(dbclick)=='function'){
					trs.dblclick(function(){
						dbclick(escape($($(this).data('rowTrs')[0]).find('td>input[name="chkSelf"]').val()),this);
					});
				}
			}catch(e){;}
		}
	});
	if($('body').width()<maxWidth){
		//$('body').width(maxWidth);
	}
}

$.fn.editTbl = function(opt,param){
	if(typeof(opt)=='string'){
		switch(opt){
		case 'options':
			return this.data('options');
		default:
			return this.each(function(){
				$.fn.editTbl.methods[opt].call(this,param);
			});
		}
	}
	else{
		opt=$.extend({},$.fn.editTbl.defaults,opt);
		opt.editor=$.extend({},$.fn.editTbl.defaults.editor,opt.editor);
		this.data('options',opt);
		return this.each($.fn.editTbl.methods.init);
	}
};
$.fn.editTbl.methods = {

		init:function(){
			var target = this;
			opt = $(this).addClass('edit-table').data('options');
			var span = $('<span style="padding:1px 14px;display:inline-block;float:left;"></span>').prependTo(opt.btnArea);
		    $('<a href="javascript:void(0)" plain=true iconCls=icon-add>添加行</a>').appendTo(span).linkbutton().click(function(){//添加行事件
		 	   var tr = $('<tr>'+$('>tbody>tr:first',target).html()+'</tr>').appendTo($('>tbody',target));//复制行
		 	   $('input,select,textarea',tr).val('').attr('checked',false);//清空所有字段的值
		 	   $.each(opt.numFields.split(','),function(i,n){//将数字字段的值填充为0
			 	   $(':hidden[name$='+n+']',tr).val('0');
		 	   });
		 	   $('td[redoinit=1]',tr).each(function(){//重新初始化控件
		 		   var th = $(this).attr('val','');//清空值
		 		   if(opt.editor[th.attr('type')]){
		 			  opt.editor[th.attr('type')](th,opt);
		 		   }
		 	   });
		 	   if(opt.addCallback&&typeof(opt.addCallback)=='function'){//添加后调用回调方法，将this指针调整为新增加的行
		 		  opt.addCallback.call(tr[0],tr);
		 	   }
		 	   if(opt.onResize&&typeof(opt.onResize)=='function'){//添加后调用大小重置事件
		 		  opt.onResize.call(target);
		 	   }
		    });
		    $('<a href="javascript:void(0)" plain=true iconCls=icon-remove>删除行</a>').appendTo(span).linkbutton().click(function(){//删除行事件
		  	   var trs = $('input[name='+opt.chkSelf+']:checked',target).parent().parent();
		  	   if($('>tbody>tr',target).length==trs.length){
		  		   $.messager.alert('提示','删除时至少要保留一行内容！');
		  		   return;
		  	   }
		  	   $.messager.confirm('提示','您确定要删除选择的 '+trs.length+' 行内容吗？',function(r){
		  		   if(r){
		  			   if(opt.delMode!='edit'){//非正常编辑模式下，加删除标记
		  				   trs.addClass(opt.delCls).find('input[name$='+opt.vcDelFlag+']').val('1');
		  			   }
		  			   else{//填报模式下直接删除行
		  	 		 	   trs.remove();
		  			   }
				 	   if(opt.delCallback&&typeof(opt.delCallback)=='function'){//添加后调用回调方法
				 		  opt.delCallback.call(trs[0],trs);
				 	   }
		  		 	   if(opt.onResize&&typeof(opt.onResize)=='function'){//添加后调用大小重置事件
		  		 		  opt.onResize.call(target);
		  		 	   }
		  		   }
		  	   });
		     });
		    if(opt.delMode!='edit'||$('>tbody>tr.'+opt.delCls,target).length>0){//在审批或有删除行的情况，增加恢复按钮
		    	$('<a href="javascript:void(0)" plain=true iconCls=icon-redo>恢复行</a>').insertAfter('#delRow').linkbutton().click(function(){
		    	 	var trs = $('>tbody>tr.'+opt.delCls+' input[name='+opt.chkSelf+']:checked',target).parent().parent();
					trs.removeClass(opt.delCls).find('input[name$='+opt.vcDelFlag+']').val('0');
		    	});
		    }
		    $('<a href="javascript:void(0)" plain=true iconCls=icon-up>上移</a>').appendTo(span).linkbutton().click(function(){
		    	$('input[name='+opt.chkSelf+']:checked',target).parent().parent().each(function(){
		  		   var prev = $(this).prev();
		  		   if(prev.length>0&&prev.find('input[name='+opt.chkSelf+']:checked').length==0){
		  			   prev.before(this);
		  		   }
		  	   });
		    });
		    $('<a href="javascript:void(0)" plain=true iconCls=icon-down>下移</a>').appendTo(span).linkbutton().click(function(){
		  	   var trs = $('input[name='+opt.chkSelf+']:checked',target).parent().parent();
		  	   for(var i=trs.length-1;i>=0;i--){
		  		   var next = $(trs[i]).next();
		  		   if(next.length>0&&next.find('input[name='+opt.chkSelf+']:checked').length==0){
		  			   next.after(trs[i]);
		  		   }
		  	   }
		    });
		    $('input[name='+opt.chkAll+']',opt.container).die('click').click(function(){
		  	   $('input[name='+opt.chkSelf+']',target).attr('checked',this.checked);
				$('>tbody>tr',target).toggleClass('sel',this.checked);
		    });
		    var data = $(target).data('data')||$(target).data('data',{}).data('data');//页面数据值缓存，用来对比值是否发生改变
		    $('>tbody>tr',target).each(function(idx){
		    	$('>td',this).each(function(){
		    	 	   var th=$(this);
		    	 	   if(opt.editor[th.attr('type')]){
		    	 		  opt.editor[th.attr('type')](th,opt);
		    	 	   }
		    	 	   if(th.attr('fun')){
		    	 		   var fun = eval(th.attr('fun'));
		    	 		   if(typeof(fun)=='function'){
		        	 		   setTimeout(function(){
		        	 			   fun.call(th);
		        	 		   },200);
		    	 		   }
		    	 	   }
		    	});
		    	if($('input[name$='+opt.vcId+']',this).val()!=''){//为每一行的值做备份，在提交时对值进行比对，进行修改人和修改时间的记录
		    		var row = data[$('input[name$='+opt.vcId+']',this).val()]={};
		     	    $('input[name],select[name],textarea[name]',this).each(function(){
		     		    row[$(this).attr('name').replace(new RegExp(opt.items+"\[\d+\]\."),'')]=$(this).attr('val')||this.value;
		     	    });
		    	}
		    });
		},
		chkRowModify:function(){
		    var data=$(this).data('data');
			opt = $(this).data('options');
		    $('>tbody>tr',this).each(function(idx,tr){
            	$('input[name],select[name],textarea[name]',this).each(function(){//修正items的索引
            		$(this).attr('name',$(this).attr('name').replace(new RegExp(opt.items+'\\[(\\d+)\\]\\.'),opt.items+'['+idx+'].'));
            	});
		    	var id = $('input[name$='+opt.vcId+']',this).val();
		    	var modifyFlag = $('input[name$='+opt.dtModify+']',this);
		    	if(modifyFlag.val()!=''&&!modifyFlag.attr('val')){
		    		modifyFlag.attr('val',modifyFlag.val());
		    	}
		    	else{//如果值为空时，将上次存储的值还原到value中
		    		modifyFlag.val(modifyFlag.attr('val'));
		    	}
		    	if(id==''||!data[id]){//如果新增行（ID为空，或在缓存中找不到记录）清空最后修改时间，后台自动将修改时间和修改人更新
		    		modifyFlag.val('');
		    	}
		    	for(var p in data[id]){
		    		if(p!='nseq'&&$('input[name$='+p+'],select[name$='+p+'],textarea[name$='+p+']',this).val()!=data[id][p]){
		        		$('input[name$='+opt.dtModify+']',this).val('');break;
		    		}
		    	}
		    	$.each(opt.numFields.split(','),function(i,n){//将隐藏的数字字段值填充为0
				    (o=$(':hidden[name$='+n+']',tr)).val(o.val()||'0');
			 	});
		    });
		}
};
$.fn.editTbl.defaults={btnArea:'#btnArea',delMode:'edit',onResize:null,chkAll:'chkAll',chkSelf:'chkSelf',vcId:'vcId',vcDelFlag:'vcDelFlag',dtModify:'dtModify',items:'items',
		idAttrs:'vcId,vcDelFlag,dtAdd,vcAdd,dtModify,vcModify',numFields:'vcDelFlag,nseq',
		addCallback:null,delCls:'itemtr1',container:'#operateWindow',cache:{},editor:{//编辑器
			vcId:function(th,opt){
			    var idAttrs = opt.idAttrs.split(',');
 	 		    for(var i=0;i<idAttrs.length;i++){
    	 		    th.append($('<input type=hidden name='+opt.items+'[0].'+idAttrs[i]+'>').val(th.attr(idAttrs[i])));
	 		    }
			},
			num:function(th,opt){
 	 		    th.html($('<input type=text name='+opt.items+'[0].'+th.attr('name')+'>').val(parseFloat(th.text())==0?'':th.text()));
			},
			linetext:function(th,opt){
 	 		    th.html($('<input type=text name='+opt.items+'[0].'+th.attr('name')+'>').val(th.text()).attr('val',th.attr('val')||''));
			},
			multitext:function(th,opt){
 	 		   th.html('<textarea name='+opt.items+'[0].'+th.attr('name')+'>'+th.text()+'</textarea>');
			},
			date:function(th,opt){
 	 		    th.html($('<input type=text class=Wdate onclick="WdatePicker({dateFmt:\''+(th.attr('fmt')||'yyyy-MM-dd')+'\'})" name='+opt.items+'[0].'+th.attr('name')+'>').val(th.text()).attr('val',th.attr('val')||''));
			},
			sel:function(th,opt){
 	 		   try{var data = eval(th.attr('data'));}catch(e){;}
	 		   data=data||th.attr('data');
	 		   var sel = $('<select name='+opt.items+'[0].'+th.attr('name')+'></select>');
	 		   sel = fillSelect(sel,data).val(th.attr('value')||th.text());
	 		   th.empty().append(sel);
			},
			ajaxFun:function(inputbox,opt,type,url,callback){
				var cacheName = type+'-data';
				if(opt.cache[cacheName]){
					if(opt.cache[cacheName].data){//如果数据已经加载回来，则直接显示
						callback.call(inputbox,opt.cache[cacheName].data);
					}
					else{//否则加入等待队列
						opt.cache[cacheName].queue.push(inputbox);
					}
				}
				else{
					opt.cache[cacheName]={queue:[inputbox],data:null};
		 		    $.getJSON(url,function(data){
			 			  $.each(opt.cache[cacheName].queue,function(i,item){
			 				  callback.call(item,opt.cache[cacheName].data=data);
			 			  });
			 		});
				}
			},
			org:function(th,opt){
 	 		    th.attr('redoinit','1').html($('<input type=text name='+opt.items+'[0].'+th.attr('name')+'>').val(th.text()).attr('val',th.attr('val')||''));
 	 		    $.fn.editTbl.defaults.editor.ajaxFun($('input',th),opt,'org','/mis/util/util_searchOrgJsonTree.action',function(data){
					this.combotree({width:this.parent().width(),valueField:'id',value:this.attr('val')||this.val(),data:data});
 	 		    });
			},
			station:function(th,opt){
 	 		    th.attr('redoinit','1').html($('<input type=text name='+opt.items+'[0].'+th.attr('name')+'>').val(th.text()).attr('val',th.attr('val')||''));
 	 		    $.fn.editTbl.defaults.editor.ajaxFun($('input',th),opt,'station','/emap/util/util_searchOrgStationJsonTree.action?flag=1',function(data){
					this.combobox({width:this.parent().width(),valueField:'id',value:this.attr('val')||this.val(),data:data});
 	 		    });
			},
			dict:function(th,opt){
 	 		    th.attr('redoinit','1').html($('<input type=text name='+opt.items+'[0].'+th.attr('name')+'>').val(th.text()).attr('val',th.attr('val')||''));
 	 		    $.fn.editTbl.defaults.editor.ajaxFun($('input',th),opt,'dict','/mis/util/util_searchSysDictJsonTree.action?dictName='+th.attr('dictName'),function(data){
					this.combobox({width:this.parent().width(),valueField:'id',value:this.attr('val')||this.val(),data:data});
 	 		    });
			}
		}
};

function fillSelect(sel,options,split1,split2){
	var cache=$(window).data('sel-cache')||$(window).data('sel-cache',{}).data('sel-cache');
	if(cache[options]){
		return $(sel).html(cache[options].html());
	}
	else{
		var ary=options.split(split1||','),htm='';
		for(var i=0;i<ary.length;i++){
			if(ary[i]=='')continue;
			var opt=ary[i].split(split2||':');opt[1]=opt[1]?opt[1]:opt[0];
			htm+='<option value="'+opt[0]+'">'+opt[1]+'</option>';
		}
		return cache[options]=$(sel).html(htm);
	}
}